package com.taxsystem.huangguangxing.taxrelatedcheck;

import com.main.taxsystem.R;
import java.util.concurrent.ExecutionException;


import org.json.JSONObject;
import com.taxsystem.huangguangxing.commoncheck.Article;
import com.taxsystem.tool.HttUtil;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.TextView;

public class TaxrelatedcheckShowArticleActivity extends Activity {

	public final static String RECI_COAST = "com.taxsystem.huangguangxing.taxrelatedcheck.http";

	String url = "http://itaxmanagerapi.duapp.com/app/article/getarticlebyid?artid=";
	TextView textViewTitle;
	TextView textViewBody;
	Article article;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.taxrelated_check_2);

		textViewTitle = (TextView) findViewById(R.id.textView1);
		textViewBody = (TextView) findViewById(R.id.textView2);

		article=new Article();
		String title_id = getIntent().getExtras().getString("taxrelatedcheck");
		url = url + title_id;

		IntentFilter filter = new IntentFilter(RECI_COAST);
		BroadcastReceiver myrecive = new MyRecive();
		registerReceiver(myrecive, filter);
		new Thread() {

			@Override
			public void run() {
				Intent intent = new Intent(RECI_COAST);
				try {
					// 获取服务器返回的信息
					String reslut = HttUtil.getRequest(url);
					intent.putExtra("taxrelatedcheck", reslut);
					// 发送广播
					sendBroadcast(intent);
				} catch (InterruptedException e) {
					e.printStackTrace();
				} catch (ExecutionException e) {
					e.printStackTrace();
				}
			}

		}.start();

	}

	private class MyRecive extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) {
			try {
				// 获取JSONObject对象
				JSONObject jsonObject_data = new JSONObject(
						intent.getStringExtra("taxrelatedcheck"));
				JSONObject jsonObject_article = new JSONObject(
						jsonObject_data.getString("data"));
				article.setArtId(jsonObject_article.getInt("artId"));
				article.setTitle(jsonObject_article.getString("title"));
				article.setSource(jsonObject_article.getString("source"));
				article.setActTypeId(jsonObject_article.getInt("actTypeId"));
				article.setActTypeName(jsonObject_article
						.getString("actTypeId"));
				article.setPublishTime(jsonObject_article
						.getString("publishTime"));
				article.setCreateTime(jsonObject_article
						.getString("createTime"));
				article.setReadCount(jsonObject_article.getInt("readCount"));
				article.setContentSummary(jsonObject_article
						.getString("contentSummary"));
				article.setContent(jsonObject_article.getString("content"));
				article.setImportant(jsonObject_article.getString("important"));
				textViewTitle.setText(article.getTitle());
				textViewBody.setText(article.getContent());

			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
